package com.healthcloud.service.impl;


import com.healthcloud.dao.BloodManagerMapper;
import com.healthcloud.dao.ChronicMapper;
import com.healthcloud.entity.*;
import com.healthcloud.service.ChronicService;
import com.healthcloud.service.DoctorService;
import com.healthcloud.service.SignPatientService;
import com.healthcloud.utils.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ChronicServiceImpl implements ChronicService {

    @Autowired
    private ChronicMapper mapper;

    @Autowired
    private SignPatientService signService;

    @Autowired
    private DoctorService doctorService;

    @Autowired
    private BloodManagerMapper bloodManagerMapper;

    @Override
    public List<SignPatientBean> searchPatient(PatientBean entity, String pageindex, String pagesize) {

        SignPatientBean signPatientBean = new SignPatientBean();

        Doctor doctor = doctorService.getDoctorByUserId(Long.valueOf(entity.getUserId()));
        if (doctor != null) {

            signPatientBean.setDoctorId(doctor.getId().toString());
        }

        signPatientBean.setRealname(entity.getName());
        List<SignPatientBean> list = signService.signSearch(signPatientBean, Integer.valueOf(pageindex), Integer.valueOf(pagesize));
        return list;
    }

    @Override
    public int countPatient(PatientBean entity) {


        SignPatientBean signPatientBean = new SignPatientBean();


        Doctor doctor = doctorService.getDoctorByUserId(Long.valueOf(entity.getUserId()));
        if (doctor != null) {

            signPatientBean.setDoctorId(doctor.getId().toString());
        }


        signPatientBean.setRealname(entity.getName());
        return signService.signSearchCount(signPatientBean);
    }

    @Override
    public List<TestResultExpBean> searchResultExp(TestResultExpBean entity) {
        List<TestResultExpBean> list = mapper.searchResultExp(entity);

        for (TestResultExpBean t : list) {
            t.setpId(entity.getpId());
        }

        return list;
    }

    @Override
    public List<DueFollowUpPlanBean> searchDueFollowUpPlan(
            DueFollowUpPlanBean entity) {
        // TODO Auto-generated method stub
        return mapper.searchDueFollowUpPlan(entity);
    }

    @Override
    public List<ChronicTestResultBean> searchTestResult(
            ChronicTestResultBean entity) {
        // TODO Auto-generated method stub
        return mapper.searchTestResult(entity);
    }

    @Override
    public List<ChronicTestResultBean> searchBpList(ChronicTestResultBean entity, PageParam pageParam) {
        // TODO Auto-generated method stub
        return mapper.searchBpList(entity,pageParam);
    }

    @Override
    public List<ChronicTestResultBean> searchBsList(ChronicTestResultBean entity, PageParam pageParam) {
        // TODO Auto-generated method stub
        return mapper.searchBsList(entity,pageParam);
    }

    @Override
    public List<SmartDataBean> searchSmartList(SmartDataBean entity, String pageindex, String pagesize) {
        // TODO Auto-generated method stub
        return mapper.searchSmartList(entity, pageindex, pagesize);
    }

    @Override
    public int countSmartList(SmartDataBean entity) {
        // TODO Auto-generated method stub
        return mapper.countSmartList(entity);
    }

    @Override
    public List<PatientBean> selectPatient(PatientBean entity,
                                           String pageindex, String pagesize) {
        // TODO Auto-generated method stub
        return mapper.selectPatient(entity, pageindex, pagesize);
    }

    @Override
    public List<CommonTestResultBean> getAllBpData(List<String> sns, CommonTestResultBean entity,
                                                   String pageindex, String pagesize) {
        // TODO Auto-generated method stub
        return mapper.getAllBpData(sns, entity, pageindex, pagesize);
    }

    @Override
    public List<CommonTestResultBean> getAllBsData(List<String> sns, CommonTestResultBean entity,
                                                   String pageindex, String pagesize) {
        // TODO Auto-generated method stub
        return mapper.getAllBsData(sns, entity, pageindex, pagesize);
    }

    @Override
    public void saveBlood(BloodManager bloodManager) {

        bloodManager.setCreateTime(new Date());
        bloodManager.setUpdateTime(new Date());

        bloodManagerMapper.save(bloodManager);
    }

    @Override
    public void updateBlood(BloodManager bloodManager) {

        bloodManager.setCreateTime(new Date());
        bloodManager.setUpdateTime(new Date());

        bloodManagerMapper.update(bloodManager);
    }

    @Override
    public List<BloodManager> queryBloodByPId(int pId, String type) {

        return bloodManagerMapper.queryBloodByPId(pId,type);
    }

    @Override
    public BloodManager getById(int id) {
        return bloodManagerMapper.get(id);
    }

    @Override
    public int count(int pId) {
        return bloodManagerMapper.count(pId);
    }

	@Override
	public int countBpList(ChronicTestResultBean bean) {
		return mapper.countBpList(bean);
	}

	@Override
	public int countBsList(ChronicTestResultBean bean) {
		return mapper.countBsList(bean);
	}
}
